import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Random;

import javax.swing.ImageIcon;
import javax.swing.Timer;


public class Enemy implements ActionListener {
	
	private Random rand;
	private ImageIcon ileft, iright;
	private Image enemyImage;
	private int x, dx, y;
	public int overallX;
	private Timer timer;
	
	public Enemy(int x, int y, int dx) {
		rand = new Random();
		timer = new Timer(rand.nextInt(1200) + 800, this);
		timer.start();
		this.x = x;
		this.overallX = x;
		this.dx = dx;
		this.y = y;
		ileft = new ImageIcon("Images/koopa left.gif");
		iright = new ImageIcon("Images/koopa right.gif");
		if (x > 750) {
			enemyImage = ileft.getImage();
		} else {
			enemyImage = iright.getImage();
		}
	}
	
	public void move() {
		
		if (x + dx == 0) {
			dx = 1;
			enemyImage = iright.getImage();
		} if (x + dx == 4096) {
			dx = -1;
			enemyImage = ileft.getImage();

		}
		
		x = x + dx;

	}
	
	//changes direction every 0 - 2 seconds 
	public void actionPerformed(ActionEvent e) {
		int dxChoice = rand.nextInt(2);
		if (dxChoice == 0) {
			dx = -1;
			enemyImage = ileft.getImage();
		} else {
			dx = 1;
			enemyImage = iright.getImage();
		}
	}
	
	public int getX() {
		return x;
	}
	
	public int getY() {
		return y;
	}
	
	public int getDX() {
		return dx;
	}
	
	public Image getImage() {
		return enemyImage;
	}



}
